<div class="col-sm-12 col-lg-6">
  <form name="roleForm"
        class="form-horizontal"
        #formDir="ngForm"
        [formGroup]="roleForm"
        novalidate>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"
            i18n>{mode, select, editing {Edit} other {Add}} Role</h3>
      </div>
      <div class="panel-body">

        <!-- Name -->
        <div class="form-group"
             [ngClass]="{'has-error': roleForm.showError('name', formDir)}">
          <label class="control-label col-sm-3"
                 for="name">
            <ng-container i18n>Name</ng-container>
            <span class="required"
                  *ngIf="mode !== roleFormMode.editing"></span>
          </label>
          <div class="col-sm-9">
            <input class="form-control"
                   type="text"
                   i18n-placeholder
                   placeholder="Name..."
                   id="name"
                   name="name"
                   formControlName="name"
                   autofocus>
            <span class="help-block"
                  *ngIf="roleForm.showError('name', formDir, 'required')"
                  i18n>This field is required.</span>
            <span class="help-block"
                  *ngIf="roleForm.showError('name', formDir, 'notUnique')"
                  i18n>The chosen name is already in use.</span>
          </div>
        </div>

        <!-- Description -->
        <div class="form-group"
             [ngClass]="{'has-error': roleForm.showError('description', formDir)}">
          <label i18n
                 class="control-label col-sm-3"
                 for="description">Description</label>
          <div class="col-sm-9">
            <input class="form-control"
                   type="text"
                   i18n-placeholder
                   placeholder="Description..."
                   id="description"
                   name="description"
                   formControlName="description">
          </div>
        </div>

        <!-- Permissions -->
        <div class="form-group">
          <label i18n
                 class="control-label col-sm-3">Permissions</label>
          <div class="col-sm-9">
            <cd-table [data]="scopes_permissions"
                      [columns]="columns"
                      columnMode="flex"
                      [toolHeader]="false"
                      [autoReload]="false"
                      [autoSave]="false"
                      [footer]="false"
                      [limit]="0">
            </cd-table>
          </div>
        </div>

      </div>
      <div class="panel-footer">
        <div class="button-group text-right">
          <cd-submit-button [form]="formDir"
                            type="button"
                            (submitAction)="submit()"
                            i18n>{mode, select, editing {Update} other {Create}} Role</cd-submit-button>
          <button i18n
                  type="button"
                  class="btn btn-sm btn-default"
                  routerLink="/user-management/roles">Back</button>
        </div>
      </div>
    </div>
  </form>
</div>

<ng-template #cellScopeCheckboxTpl
             let-column="column"
             let-row="row"
             let-value="value">
  <div class="checkbox checkbox-primary">
    <input id="scope_{{ row.scope }}"
           type="checkbox"
           [checked]="isRowChecked(row.scope)"
           (change)="onClickCellCheckbox(row.scope, column.prop, $event)">
    <label class="datatable-permissions-scope-cell-label"
           for="scope_{{ row.scope }}">{{ value }}</label>
  </div>
</ng-template>

<ng-template #cellPermissionCheckboxTpl
             let-column="column"
             let-row="row"
             let-value="value">
  <div class="checkbox checkbox-primary">
    <input type="checkbox"
           [checked]="value"
           (change)="onClickCellCheckbox(row.scope, column.prop, $event)">
    <label></label>
  </div>
</ng-template>

<ng-template #headerPermissionCheckboxTpl
             let-column="column">
  <div class="checkbox checkbox-primary">
    <input id="header_{{ column.prop }}"
           type="checkbox"
           [checked]="isHeaderChecked(column.prop)"
           (change)="onClickHeaderCheckbox(column.prop, $event)">
    <label class="datatable-permissions-header-cell-label"
           for="header_{{ column.prop }}">{{ column.name }}</label>
  </div>
</ng-template>
